﻿using System;
using System.ComponentModel;

namespace YArchitech.Electric.Controls
{
	public class HYPropertyDescriptor : PropertyDescriptor
	{
		public HYPropertyDescriptor(ref HYProperty property, Attribute[] attrs) : base(property.Name, attrs)
		{
			this._Property = property;
		}

		public override bool CanResetValue(object component)
		{
			return false;
		}

		public override Type ComponentType
		{
			get
			{
				return null;
			}
		}

		public override object GetValue(object component)
		{
			return this._Property.Value;
		}

		public override void SetValue(object component, object value)
		{
			this._Property.Value = value;
		}

		public override string Category
		{
			get
			{
				return this._Property.Category;
			}
		}

		public override string DisplayName
		{
			get
			{
				if (!string.IsNullOrEmpty(this._Property.DisplayName))
				{
					return this._Property.DisplayName;
				}
				return this._Property.Name;
			}
		}

		public override string Description
		{
			get
			{
				return this._Property.Description;
			}
		}

		public override bool IsReadOnly
		{
			get
			{
				return this._Property.ReadOnly;
			}
		}

		public override void ResetValue(object component)
		{
		}

		public override Type PropertyType
		{
			get
			{
				return this._Property.Value.GetType();
			}
		}

		public override bool ShouldSerializeValue(object component)
		{
			return false;
		}

		public override TypeConverter Converter
		{
			get
			{
				return this._Property.Converter;
			}
		}

		public override object GetEditor(Type editorBaseType)
		{
			if (this._Property.Editor != null)
			{
				return this._Property.Editor;
			}
			return base.GetEditor(editorBaseType);
		}

		private HYProperty _Property;
	}
}
